package com.sk.bilibili.model.fragment.main.collect;

import com.sk.api.annotations.Autowired;
import com.sk.bilibili.bean.FollowThem;
import com.sk.bilibili.callBack.RequestCallBack;
import com.sk.bilibili.dto.Page;
import com.sk.bilibili.mapper.FollowThemMapper;
import com.sk.bilibili.model.BaseModel;
import com.sk.bilibili.other.JsonMap;
import com.sk.bilibili.utils.RequestUtils;
import com.sk.bilibili.view.fragment.main.collect.FollowThemFragment;

public class FollowThemModel extends BaseModel<FollowThemFragment> {

    @Autowired
    FollowThemMapper followThemMapper;
    private int page=1;
    private int size=10;
    private Integer state=1;

    public void setState(Integer state, Integer typeId) {
        this.state=state;
        refresh(typeId);
    }

    public void refresh(Integer typeId) {
        page=1;
        JsonMap map=getJsonMap(typeId);
        RequestUtils.process(followThemMapper.getFollowThem(map), followThemPage -> {
            view.refreshSuccess(followThemPage.getRecords());
            page++;
        });
    }

    private JsonMap getJsonMap(Integer typeId) {
        JsonMap map=new JsonMap();
        map.put("page",page);
        map.put("size",size);
        map.put("state",state);
        map.put("typeId",typeId);
        return map;
    }

    public void loadData(Integer typeId) {
        JsonMap map=getJsonMap(typeId);
        RequestUtils.process(followThemMapper.getFollowThem(map), followThemPage -> {
            view.loadMoreSuccess(followThemPage.getRecords());
            page++;
        });
    }

}